/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-11-06     SummerGift   change to new framework
 */

#include <rtthread.h>
#include <board.h>
#include "main.h"
#include "rtdevice.h"
#include "drv_gpio.h"

#define LED_PIN GET_PIN(C,6)
#define KEY_PIN GET_PIN(A,0)

void key_hdr(void *args)
{
    if(rt_pin_read(KEY_PIN) == 1)
    {
        rt_kprintf("%s is press\n",(char *)args);
    }
    else if(rt_pin_read(KEY_PIN) == 0)
    {
        rt_kprintf("%s is release\n",(char *)args);
    }
}

int main(void)
{
    rt_pin_mode(LED_PIN,PIN_MODE_OUTPUT);
    rt_pin_mode(KEY_PIN,PIN_MODE_INPUT_PULLDOWN);
    rt_pin_attach_irq(KEY_PIN,PIN_IRQ_MODE_RISING_FALLING,key_hdr,(void *)"key");
    rt_pin_irq_enable(KEY_PIN, PIN_IRQ_ENABLE);
    while(1)
    {
        rt_pin_write(LED_PIN,1);
        rt_thread_mdelay(50);
        rt_pin_write(LED_PIN,0);
        rt_thread_mdelay(200);
        rt_pin_write(LED_PIN,1);
        rt_thread_mdelay(50);
        rt_pin_write(LED_PIN,0);
        rt_thread_mdelay(1500);     
    }
//    return 0;
}
